{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e1f1c513",
   "metadata": {},
   "outputs": [],
   "source": [
    "dct ={'学号':'211634410','姓名':'lulu','年龄':19}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4dbfee78",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'lulu'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dct['姓名']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "79656e21",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "'性别'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "Input \u001b[1;32mIn [3]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mdct\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m性别\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\n",
      "\u001b[1;31mKeyError\u001b[0m: '性别'"
     ]
    }
   ],
   "source": [
    "dct['性别']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a2e067da",
   "metadata": {},
   "outputs": [],
   "source": [
    "dct['性别']='女'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "37f63a60",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'学号': '211634410', '姓名': 'lulu', '年龄': 19, '性别': '女'}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dct"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "763ba1cd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['__class__',\n",
       " '__class_getitem__',\n",
       " '__contains__',\n",
       " '__delattr__',\n",
       " '__delitem__',\n",
       " '__dir__',\n",
       " '__doc__',\n",
       " '__eq__',\n",
       " '__format__',\n",
       " '__ge__',\n",
       " '__getattribute__',\n",
       " '__getitem__',\n",
       " '__gt__',\n",
       " '__hash__',\n",
       " '__init__',\n",
       " '__init_subclass__',\n",
       " '__ior__',\n",
       " '__iter__',\n",
       " '__le__',\n",
       " '__len__',\n",
       " '__lt__',\n",
       " '__ne__',\n",
       " '__new__',\n",
       " '__or__',\n",
       " '__reduce__',\n",
       " '__reduce_ex__',\n",
       " '__repr__',\n",
       " '__reversed__',\n",
       " '__ror__',\n",
       " '__setattr__',\n",
       " '__setitem__',\n",
       " '__sizeof__',\n",
       " '__str__',\n",
       " '__subclasshook__',\n",
       " 'clear',\n",
       " 'copy',\n",
       " 'fromkeys',\n",
       " 'get',\n",
       " 'items',\n",
       " 'keys',\n",
       " 'pop',\n",
       " 'popitem',\n",
       " 'setdefault',\n",
       " 'update',\n",
       " 'values']"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dir(dct)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "c892f1b1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'学号': '211634410', '姓名': 'lulu', '年龄': 19, '性别': '女'}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dct"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "e4014181",
   "metadata": {},
   "outputs": [],
   "source": [
    "dct2 = dct.copy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "71f46a81",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'学号': '211634410', '姓名': 'lulu', '年龄': 19, '性别': '女'}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dct2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "787cae2e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dct==dct2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "d6546bdd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "19"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dct2.get('年龄')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "de87b856",
   "metadata": {},
   "outputs": [],
   "source": [
    "x=dct.pop('年龄')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "844a63df",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'学号': '211634410', '姓名': 'lulu', '年龄': 19, '性别': '女'}"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dct2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "0a853043",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'学号': '211634410', '姓名': 'lulu', '性别': '女'}"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dct"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "ef36b6ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['学号', '姓名', '性别'])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dct.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "56557033",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "学号\n",
      "姓名\n",
      "年龄\n",
      "性别\n"
     ]
    }
   ],
   "source": [
    "for k in dct2.keys():\n",
    "    print(k)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "2b914f43",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_values(['211634410', 'lulu', 19, '女'])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dct2.values()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "7d6cec72",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_items([('学号', '211634410'), ('姓名', 'lulu'), ('性别', '女')])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dct.items()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "61e60cb9",
   "metadata": {},
   "outputs": [],
   "source": [
    "s='Python is an easy to learn,powerful programming language.It has efficient high-level data structures and a simple but effective approach to object-oriented programming.'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "eebc45f5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'p': 7, 'y': 2, 't': 12, 'h': 5, 'o': 9, 'n': 9, ' ': 21, 'i': 10, 's': 6, 'a': 14, 'e': 16, 'l': 6, 'r': 10, ',': 1, 'w': 1, 'f': 5, 'u': 5, 'g': 7, 'm': 5, '.': 2, 'c': 5, '-': 2, 'v': 2, 'd': 3, 'b': 2, 'j': 1}\n"
     ]
    }
   ],
   "source": [
    "dct={ }\n",
    "for c in s.lower():\n",
    "    dct[c]=dct.get(c,0)+1\n",
    "print(dct)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "3cb8022c",
   "metadata": {},
   "outputs": [],
   "source": [
    "lst = sorted(dct.items(),key=lambda x:x[1],reverse=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "4e01b653",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(' ', 21),\n",
       " ('e', 16),\n",
       " ('a', 14),\n",
       " ('t', 12),\n",
       " ('i', 10),\n",
       " ('r', 10),\n",
       " ('o', 9),\n",
       " ('n', 9),\n",
       " ('p', 7),\n",
       " ('g', 7),\n",
       " ('s', 6),\n",
       " ('l', 6),\n",
       " ('h', 5),\n",
       " ('f', 5),\n",
       " ('u', 5),\n",
       " ('m', 5),\n",
       " ('c', 5),\n",
       " ('d', 3),\n",
       " ('y', 2),\n",
       " ('.', 2),\n",
       " ('-', 2),\n",
       " ('v', 2),\n",
       " ('b', 2),\n",
       " (',', 1),\n",
       " ('w', 1),\n",
       " ('j', 1)]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "57274fd7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
